﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using NSQL.Sharpen;

namespace NSQL.Expressions.Functions
{
    public class LengthFunction : BaseExpression, ILengthFunction
    {
        public IStringExpression Expr { get; }

        public LengthFunction(IStringExpression expression)
        {
            Expr = expression;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
        public override bool IsValid => Expr.IsValid;
        protected override IExpression DeepCopy()
        {
            return new LengthFunction(Expr.DeepClone())
            {
                Tag = Tag
            };
        }

        public static ArithmeticExpression operator +(LengthFunction left, IIntegerExpression right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Plus);
            
        }

        public static ArithmeticExpression operator +(LengthFunction left, IntegerExpression right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Plus);
        }

        public static ArithmeticExpression operator +(IntegerExpression left,  LengthFunction right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Plus);
        }
        
        
        public static ArithmeticExpression operator -(LengthFunction left, IIntegerExpression right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Minus);
            
        }

        public static ArithmeticExpression operator -(LengthFunction left, IntegerExpression right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Minus);
        }
        public static ArithmeticExpression operator -(IntegerExpression left, LengthFunction right)
        {
            return new ArithmeticExpression(left, right, ArithmeticOperator.Minus);
        }
    }
}